﻿Imports ccapps.persistent.ServiceHistory
Public Class ServiceHistory
    Inherits System.Web.UI.Page
    Dim ps As Integer = 0
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("user") = "" Or Session("user") Is Nothing Then
            Session("message") = "!!Session Timeout!!,Tekrar Giriş Yapmalısınız"
            Response.Clear()
            Response.Status = "302 Object Moved"
            Response.RedirectLocation = "CX_Exception.aspx"
            Response.End()
        End If
    End Sub

    Protected Sub BtnCustcode_Click(sender As Object, e As EventArgs) Handles BtnCustcode.Click
        Try
            ErrorMes.Text = ""
            Table3.Visible = False
            Table4.Visible = False
            Tableson.Visible = False
            GridView2.SelectedIndex = -1


            Dim dt As DataTable = getcustomerInfoFromCustcode(TxtCustcode.Text)


            If dt.Rows.Count > 1 Then
                GridView5.DataSource = dt
                GridView5.DataBind()
                contractlist.Visible = True

            Else
                If dt.Rows.Count > 0 Then
                    Table2.Visible = True
                    LblActive.Text = dt.Rows(0)("STATUS").ToString()
                    LblCoid.Text = dt.Rows(0)("COID").ToString()
                    LblSigned.Text = dt.Rows(0)("SIGNED").ToString()
                    LblLang.Text = dt.Rows(0)("DES").ToString()
                    LblRateplan.Text = dt.Rows(0)("RTDES").ToString()
                    Lbltmcode.Text = dt.Rows(0)("TMCODE").ToString()

                    Dim dt2 As DataTable = GetCustInfo2FromCustcode(TxtCustcode.Text)
                    LblCustomer.Text = dt2.Rows(0)("NAME").ToString() + "  " + dt2.Rows(0)("LNAME").ToString() + "  " + dt2.Rows(0)("CITY").ToString()
                    Dim dt5 As DataTable = ContractReason(Convert.ToInt32(LblCoid.Text))
                    LblReason.Text = dt5.Rows(0)(0).ToString()

                    Dim dt3 As DataTable = ServicePackList(Convert.ToInt32(Lbltmcode.Text))
                    RadioButtonList1.Items.Clear()
                    If dt3.Rows.Count > 0 Then
                        For Each dr As DataRow In dt3.Rows
                            RadioButtonList1.Items.Add(New ListItem(dr("des").ToString(), dr("spcode").ToString()))
                            'DDL_CompReason.Items.Add(New ListItem(dr("DESCRIPTION").ToString(), dr("REASON_ID").ToString()))

                        Next


                    End If

                Else
                    ' Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('Girmiş Olduğunuz CUSTCODE' a Ait Veri Bulunamamıştır.');</script>")
                    ErrorMes.Text = "Girmiş Olduğunuz CUSTCODE' a Ait Veri Bulunamamıştır."
                End If

            End If


           
          
        Catch ex As Exception
            ErrorMes.Text = ex.Message()
        End Try
      


    End Sub


   
    Protected Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        Try

            Tableson.Visible = False
            ErrorMes.Text = ""
            GridView2.SelectedIndex = -1


            Dim dt As DataTable = ServiceHist(Convert.ToInt32(LblCoid.Text), Convert.ToInt32(Lbltmcode.Text), RadioButtonList1.SelectedItem.Value)
            GridView2.DataSource = dt
            GridView2.DataBind()
            Table4.Visible = False
            Table3.Visible = True
            Tableson.Visible = False

        Catch ex As Exception
            ErrorMes.Text = "Yaptığınız  işlemde hata oluşmuştur lütfen tekrar deneyiniz"
        End Try
    End Sub

    Protected Sub OnRowCreated(sender As Object, e As GridViewRowEventArgs)

    End Sub

    Protected Sub GridView2_RowCommand(sender As Object, e As GridViewCommandEventArgs)

        Try

            If e.CommandName = "view" Then
                Table4.Visible = True

            End If

        Catch ex As Exception


            Session("message") = ex.Message
            Response.Clear()
            Response.Status = "302 Object Moved"
            Response.RedirectLocation = "CX_Exception.aspx"
            Response.End()




        End Try
    End Sub

    Protected Sub GridView2_DataBound(sender As Object, e As EventArgs)

    End Sub

    Protected Sub GridView2_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView2.RowDataBound



        Dim deneme As Label = e.Row.FindControl("Label3")
        Dim deneme2 As Label = e.Row.FindControl("Label4")
        'Dim img As System.Drawing.Image = e.Row.FindControl("")


        Dim rowView As DataRowView = CType(e.Row.DataItem, DataRowView)

        'Dim imagePath As String = rowView("image_path")





        Dim deneme3 As Label = e.Row.FindControl("Label5")
        Dim deneme4 As Label = e.Row.FindControl("Label6")
        Dim deneme5 As Label = e.Row.FindControl("Label7")
        Dim deneme6 As Label = e.Row.FindControl("Label8")
        'Dim deneme7 As Label = e.Row.FindControl("Label9")



        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim id As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "SNCODE").ToString())
            Dim dt As DataTable = New DataTable()

            dt = ServiceHistControl(Convert.ToInt32(LblCoid.Text), id, Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PROFILEID").ToString()))

            Try
                Dim dt2 As DataTable = ServiceHist2(Convert.ToInt32(LblCoid.Text), id, RadioButtonList1.SelectedItem.Value, Convert.ToInt32(Lbltmcode.Text))
                deneme3.Text = Math.Round(Convert.ToDouble(dt2.Rows(0)("ONETIME").ToString()), 2).ToString() + " " + dt2.Rows(0)("ONETIMEMONEY").ToString()
                deneme4.Text = Math.Round(Convert.ToDouble(dt2.Rows(0)("Recurring").ToString()), 2).ToString() + " " + dt2.Rows(0)("RecurringMONEY").ToString()
                If dt2.Rows(0)("INITIAL").ToString() = "" Then
                    deneme5.Text = "--"
                Else
                    deneme5.Text = Math.Round(Convert.ToDouble(dt2.Rows(0)("INITIAL").ToString()), 2).ToString() + " " + dt2.Rows(0)("INITIALMONEY").ToString()
                End If



                'deneme.Text = LblCoid.Text + " " + id + " " + Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PROFILEID").ToString()).ToString()

            Catch ex As Exception
                deneme3.Text = "--"
                deneme4.Text = "--"
                deneme5.Text = "--"
                deneme.Text = "--"


            End Try
            If RadioButtonList1.SelectedItem.Value = 10 Then
                deneme3.Text = "0 TRY"
                deneme4.Text = "0 TRY"

            End If

            'deneme.Text = Convert.ToInt32(LblCoid.Text).ToString() + "  " + id.ToString() + " " + Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PROFILEID").ToString()).ToString()

            deneme.Text = dt.Rows(0)(0).ToString()


            If deneme.Text = "" Then
                deneme.Text = "Active"
            End If
            Dim strImageUrl As String

            If deneme.Text = "Active" Then
                strImageUrl = "..\images\active.png"
            Else
                strImageUrl = "..\images\deactive.png"


            End If
            Dim imageFile As System.Web.UI.WebControls.Image = CType(e.Row.FindControl("Image1"), System.Web.UI.WebControls.Image)
            imageFile.ImageUrl = strImageUrl



            If deneme.Text = "Active" Or deneme.Text = "Deactive" Or deneme.Text = "Suspend" Then
                deneme2.Text = "--"
            Else
                deneme2.Text = ""

            End If





        End If
    End Sub


    Protected Sub GridView2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView2.SelectedIndexChanged


        Dim row As GridViewRow = GridView2.SelectedRow

        ' Display the first name from the selected row.
        ' In this example, the third column (index 2) contains
        ' the first name.
        ' Response.Write("you selected" + row.Cells(2).Text)
        Table4.Visible = True
        LblServiceName.Text = row.Cells(2).Text
        LblCurrentStatus.Text = row.Cells(4).Text
        LblRtPlan.Text = LblRateplan.Text
        LblProfile.Text = row.Cells(3).Text

        'Dim dt As DataTable = ServiceHistExtraInfo(Convert.ToInt32(LblCoid.Text), LblServiceName.Text, Convert.ToInt32(Lbltmcode.Text), row.Cells(3).Text)
        ServiceExtraInfo(LblCoid.Text, row.Cells(1).Text, Lbltmcode.Text, row.Cells(3).Text)
        Tableson.Visible = False


            Try
                Dim dtServiceNameList As DataTable = ServiceNameList(Convert.ToInt32(LblCoid.Text), Convert.ToInt32(row.Cells(1).Text))
                LblSncode.Text = row.Cells(1).Text
                If dtServiceNameList.Rows.Count > 0 Then
                    GridView4.DataSource = dtServiceNameList
                    GridView4.DataBind()
                    GridView4.Visible = True
                Else
                    GridView4.Visible = False

                End If

               
            Catch ex As Exception

        End Try



    End Sub

    Private Sub ServiceExtraInfo(ByVal coid As String, ByVal servicename As String, ByVal tmcode As String, ByVal profile As String)

        Dim dt As DataTable = ServiceHistExtraInfo(Convert.ToInt32(coid), Convert.ToInt32(servicename), Convert.ToInt32(tmcode), profile)
        'Label9.Text = LblCoid.Text + "     " + LblServiceName.Text + "              " + Lbltmcode.Text + "                  " + row.Cells(3).Text


        If dt.Rows.Count > 0 Then
            LblCoreService.Text = dt.Rows(0)(0).ToString()
            LblValidFrom.Text = dt.Rows(0)(1).ToString()
            Label9.Text = dt.Rows(0)(2).ToString() 'profileid
            Label10.Text = dt.Rows(0)(3).ToString() 'sncode
        Else
            'Response.Write(coid + "-- " + servicename + "--" + tmcode + "--" + profile)
        End If

    End Sub
    Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
        'Dim strImageUrl As String
        'If e.Row.RowType = DataControlRowType.DataRow Then
        '    If DataBinder.Eval(e.Row.DataItem, "status").ToString() = "Active" Then
        '        strImageUrl = "..\images\active.png"
        '    Else
        '        strImageUrl = "..\images\deactive.png"

        '        Dim imageFile As System.Web.UI.WebControls.Image = CType(e.Row.FindControl("Image2"), System.Web.UI.WebControls.Image)
        '        imageFile.ImageUrl = strImageUrl


        '    End If


        'End If
    End Sub

    Protected Sub GridView2_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridView2.PageIndexChanging
        GridView2.PageIndex = e.NewPageIndex
        Dim dt As DataTable = ServiceHist(Convert.ToInt32(LblCoid.Text), Convert.ToInt32(Lbltmcode.Text), RadioButtonList1.SelectedItem.Value)
        GridView2.DataSource = dt
        GridView2.DataBind()
        GridView5.SelectedIndex = -1

    End Sub

    Protected Sub BtnMsisdn_Click(sender As Object, e As EventArgs) Handles BtnMsisdn.Click
        Try
            ErrorMes.Text = ""
            Table3.Visible = False
            Table4.Visible = False
            Tableson.Visible = False
            GridView2.SelectedIndex = -1

            Dim dt As DataTable = getcustomerInfoFromMSISDN(TxtMsisdn.Text)
            If dt.Rows.Count > 0 Then
                Table2.Visible = True
                LblActive.Text = dt.Rows(0)("STATUS").ToString()
                LblCoid.Text = dt.Rows(0)("COID").ToString()
                LblSigned.Text = dt.Rows(0)("SIGNED").ToString()
                LblLang.Text = dt.Rows(0)("DES").ToString()
                LblRateplan.Text = dt.Rows(0)("RTDES").ToString()
                Lbltmcode.Text = dt.Rows(0)("TMCODE").ToString()

                Dim dt2 As DataTable = GetCustInfo2FromMSISDN(TxtMsisdn.Text)
                LblCustomer.Text = dt2.Rows(0)("NAME").ToString() + "  " + dt2.Rows(0)("LNAME").ToString() + "  " + dt2.Rows(0)("CITY").ToString()
                Dim dt5 As DataTable = ContractReason(Convert.ToInt32(LblCoid.Text))
                LblReason.Text = dt5.Rows(0)(0).ToString()
                Dim dt3 As DataTable = ServicePackList(Convert.ToInt32(Lbltmcode.Text))
                RadioButtonList1.Items.Clear()
                If dt3.Rows.Count > 0 Then
                    For Each dr As DataRow In dt3.Rows
                        RadioButtonList1.Items.Add(New ListItem(dr("des").ToString(), dr("spcode").ToString()))
                        'DDL_CompReason.Items.Add(New ListItem(dr("DESCRIPTION").ToString(), dr("REASON_ID").ToString()))

                    Next
                End If


            Else
                ' Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('Girmiş Olduğunuz CUSTCODE' a Ait Veri Bulunamamıştır.');</script>")
                ErrorMes.Text = "Girmiş Olduğunuz MSISDN' e Ait Veri Bulunamamıştır."
            End If





        Catch ex As Exception
            ErrorMes.Text = ex.Message
        End Try
       
    End Sub

    Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) Handles LinkButton1.Click
        Tableson.Visible = True

        Try
            Dim dt2 As DataTable = ServiceHistExtraInfo2(Convert.ToInt32(Label9.Text), Convert.ToInt32(Label10.Text), Convert.ToInt32(LblCoid.Text))

            GridView1.DataSource = dt2
            GridView1.DataBind()
        Catch ex As Exception
            ErrorMes.Text = ex.Message
        End Try

    End Sub

 
    Protected Sub GridView5_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridView5.PageIndexChanging
        GridView5.PageIndex = e.NewPageIndex
        Dim dt As DataTable = getcustomerInfoFromCustcode(TxtCustcode.Text)
        GridView5.DataSource = dt
        GridView5.DataBind()
    End Sub

    Protected Sub GridView5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView5.SelectedIndexChanged
        Table2.Visible = False
        Table3.Visible = False
        Table4.Visible = False
        Tableson.Visible = False


        Dim row As GridViewRow = GridView5.SelectedRow
        Dim dt As DataTable = GetCustInfoFromCoid(Convert.ToInt32(row.Cells(1).Text))
        Try
            If dt.Rows.Count > 0 Then
                Table2.Visible = True
                LblActive.Text = dt.Rows(0)("STATUS").ToString()
                LblCoid.Text = dt.Rows(0)("COID").ToString()
                LblSigned.Text = dt.Rows(0)("SIGNED").ToString()
                LblLang.Text = dt.Rows(0)("DES").ToString()
                LblRateplan.Text = dt.Rows(0)("RTDES").ToString()
                Lbltmcode.Text = dt.Rows(0)("TMCODE").ToString()

                Dim dt2 As DataTable = GetCustInfo2FromCustcode(TxtCustcode.Text)
                LblCustomer.Text = dt2.Rows(0)("NAME").ToString() + "  " + dt2.Rows(0)("LNAME").ToString() + "  " + dt2.Rows(0)("CITY").ToString()
                Dim dt5 As DataTable = ContractReason(Convert.ToInt32(LblCoid.Text))
                LblReason.Text = dt5.Rows(0)(0).ToString()

                Dim dt3 As DataTable = ServicePackList(Convert.ToInt32(Lbltmcode.Text))
                RadioButtonList1.Items.Clear()
                If dt3.Rows.Count > 0 Then
                    For Each dr As DataRow In dt3.Rows
                        RadioButtonList1.Items.Add(New ListItem(dr("des").ToString(), dr("spcode").ToString()))
                        'DDL_CompReason.Items.Add(New ListItem(dr("DESCRIPTION").ToString(), dr("REASON_ID").ToString()))

                    Next


                End If

            Else
                ' Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('Girmiş Olduğunuz CUSTCODE' a Ait Veri Bulunamamıştır.');</script>")
                ErrorMes.Text = "Girmiş Olduğunuz CUSTCODE' a Ait Veri Bulunamamıştır."
            End If


        Catch ex As Exception

        End Try

    End Sub

    Protected Sub GridView4_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView4.RowDataBound
        Dim ServiceValue As Label = e.Row.FindControl("Label3")
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim dt As DataTable = New DataTable()
            'If LblSncode.Text <> "1016" Then 
            If LblSncode.Text <> "1016" Then
                dt = ServiceNameList2(Convert.ToInt32(LblCoid.Text), Convert.ToInt32(LblSncode.Text), Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PARAMETER_ID").ToString()))


                Try
                    ServiceValue.Text = dt.Rows(0)(0).ToString()
                    If ServiceValue.Text = "N" Then
                        ServiceValue.Text = "No"

                    End If
                    If ServiceValue.Text = "" Then
                        ServiceValue.Text = "--"
                    End If



                Catch ex As Exception

                    ServiceValue.Text = "--"


                End Try
            Else
                dt = ServiceNameList3(Convert.ToInt32(LblCoid.Text), Convert.ToInt32(LblSncode.Text), Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PARAMETER_ID").ToString()), LblProfile.Text)
                Try
                    ServiceValue.Text = dt.Rows(0)(0).ToString()

                Catch ex As Exception
                    ServiceValue.Text = "--"
                End Try

            End If

           
            ' Else
            'dt = ServiceNameList3(Convert.ToInt32(LblCoid.Text), Convert.ToInt32(LblSncode.Text), Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "PARAMETER_ID").ToString()), Convert.ToInt32(LblProfile.Text))
            'Try
            '    ServiceValue.Text = LblCoid.Text + "--" + LblSncode.Text + "--" + DataBinder.Eval(e.Row.DataItem, "PARAMETER_ID").ToString() + "--" + LblProfile.Text


            'Catch ex As Exception
            '    ServiceValue.Text = "--"
            'End Try
            'End If













        End If
    End Sub
End Class